﻿<UserControl x:Class="yaTDL.TaskListControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:yaTDL.Core.Converters;assembly=yaTDL.Core"
             xmlns:local="clr-namespace:yaTDL"
             xmlns:localControls="clr-namespace:yaTDL.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             x:Name="userControl">
    
    <UserControl.Resources>
        
        <!--Definition of Binding Converters-->
        <converters:DateTimeStringConverter x:Key="dateTimeStringConverter" />
        <converters:BoolVisibilityConverter x:Key="boolVisibilityConverter" />        
        <local:DateTimeColorConverter x:Key="dateTimeColorConverter"/>
        <local:PriorityColorConverter x:Key="priorityColorConverter"/>
        <local:InHistoryValueConverter x:Key="inHistoryValueConverter"/>
        <local:SortByToStringConverter x:Key="sortByConverter"/>
        <local:DoubleAdder x:Key="doubleAdder"/>
        <local:DoubleCalculator x:Key="doubleCalculator"/>
        <local:VisibilityDoubleConverter x:Key="visibilityDoubleConverter"/>

        
        <!--DataTemplate used to display a Task in a ListBox-->
        <DataTemplate x:Key="TaskListItemTemplate" >                       
            <Grid Height="27">                                   
                <CheckBox VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,0,0" IsChecked="{Binding Completed, UpdateSourceTrigger=PropertyChanged}"/>
                <TextBlock FontSize="13" Margin="25,-1,110,0" HorizontalAlignment="Stretch" VerticalAlignment="Center" Text="{Binding Content}" />
                <Border HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,33,0" Width="80" BorderThickness="1,1,0,1">
                    <Border.BorderBrush>
                        <MultiBinding Converter="{StaticResource dateTimeColorConverter}" ConverterParameter="BorderBrush" FallbackValue="Transparent">
                            <Binding Path="DueDate"/>
                            <Binding Path="Completed" />
                        </MultiBinding>
                    </Border.BorderBrush>
                    <Border.Background>
                        <MultiBinding Converter="{StaticResource dateTimeColorConverter}" ConverterParameter="Background">
                            <Binding Path="DueDate"/>
                            <Binding Path="Completed"/>
                        </MultiBinding>
                    </Border.Background>
                    <TextBlock FontSize="13" FontFamily="Segoe UI" Text="{Binding DueDate, Converter={StaticResource dateTimeStringConverter}}" HorizontalAlignment="Center">
                        <TextBlock.Foreground>
                            <MultiBinding Converter="{StaticResource dateTimeColorConverter}" ConverterParameter="Foreground">
                                <Binding Path="DueDate"/>
                                <Binding Path="Completed"/>
                            </MultiBinding>
                        </TextBlock.Foreground>
                    </TextBlock>
                </Border>
                <Border Width="25" HorizontalAlignment="Right" Margin="0,0,8,0" VerticalAlignment="Center" BorderThickness="1">
                    <Border.BorderBrush>
                        <MultiBinding Converter="{StaticResource priorityColorConverter}" ConverterParameter="BorderBrush" FallbackValue="Transparent">
                            <Binding Path="Priority"/>
                            <Binding Path="Completed"/>
                        </MultiBinding>
                    </Border.BorderBrush>
                    <Border.Background>
                        <MultiBinding Converter="{StaticResource priorityColorConverter}" ConverterParameter="Background">
                            <Binding Path="Priority"/>
                            <Binding Path="Completed"/>
                        </MultiBinding>
                    </Border.Background>
                    <TextBlock Text="{Binding Priority}" HorizontalAlignment="Center"  FontSize="13">
                        <TextBlock.Foreground>
                            <MultiBinding Converter="{StaticResource priorityColorConverter}" ConverterParameter="Foreground">
                                <Binding Path="Priority"/>
                                <Binding Path="Completed"/>
                            </MultiBinding>
                        </TextBlock.Foreground>
                    </TextBlock>
                </Border>
            </Grid>
        </DataTemplate>
        
        
        <ContextMenu x:Key="TaskContextMenu">
            <MenuItem Header="Edit" Command="{Binding ShowDetailsPaneCommand}" />
            <MenuItem Header="Delete" Command="{Binding DeleteTaskCommand}" />          
        </ContextMenu>

    </UserControl.Resources>
    
    <Grid Name="grid">

        <Grid Margin="0,45,0,38">
        	
        	<Grid.ColumnDefinitions>
        		<ColumnDefinition Width="*"  />
        		<ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="{Binding DetailsPaneVisibility, ConverterParameter=200, Converter={StaticResource visibilityDoubleConverter}}" x:Name="detailsPane" />
        	</Grid.ColumnDefinitions>
        
		
		<GridSplitter HorizontalAlignment="Right" 
                  VerticalAlignment="Stretch" 
                  Grid.Column="1" ResizeBehavior="PreviousAndNext"
                  Width="5" Background="Transparent"/>
        
		
		<Border  Grid.Column="2"                 
                BorderThickness="1,0,0,0" BorderBrush="{StaticResource Application_BorderBrush}"  Background="White">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Label Content="EDIT TASK" FontSize="12" FontFamily="Segoe WP" FontWeight="Bold" Margin="2,2,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" />
                                    
                <ScrollViewer  DataContext="{Binding SelectedTask}" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,20,0,0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                    <StackPanel>
                        <TextBox BorderBrush="Gray" Margin="8,20,8,0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Text="{Binding Content, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap"/>
                        <DatePicker BorderBrush="Gray" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Background="White" Height="25" 
                            HorizontalAlignment="Left" VerticalAlignment="Center" Margin="8,16,8,0" 
                            SelectedDate="{Binding DueDate, UpdateSourceTrigger=PropertyChanged}"/>
                        <Label Content="{Binding Priority}" HorizontalContentAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Top" 
                               ContentStringFormat="Priority: {0}" Margin="8,16,0,0" Height="30"/>
                        <Slider Background="Transparent" Width="115" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Height="22" 
                                VerticalAlignment="Top" Margin="8,0,0,0" Maximum="3" Minimum="-1" IsSnapToTickEnabled="True" TickFrequency="1"
                                Value="{Binding Priority, UpdateSourceTrigger=PropertyChanged}"/>
                    </StackPanel>
                </ScrollViewer>
                <Button Content="X" FontWeight="Bold" FontSize="15" FontFamily="Segoe WP" Style="{StaticResource ButtonStyle_Metro}" 
                        Command="{Binding CloseDetailsPaneCommand}"  HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,8,8,0" ToolTip="Close Details Pane" />
            </Grid>
        </Border>
			
        
        
        <TabControl x:Name="tabControl" Grid.Column="0" Style="{DynamicResource HeaderlessTabControl}">                        
            <TabItem Header=" all" IsSelected="{Binding AllItemsViewIsVisible}">
                <Grid Margin="0,10,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">                    
                    <localControls:ListHeaderControl Text="{Binding AllItems.Count, StringFormat=' \{0\} TASKS '}" 
                                                     SortButtonText="{Binding AllItemsSort, Converter={StaticResource sortByConverter}, StringFormat=BY \{0\}}"
                                                     SortButtonCommand="{Binding SortAllItemsCommand}" Margin="0,-10,8,0" VerticalAlignment="Top"/>
                    <ListBox
                                 BorderThickness="0"
                                 Margin="0,22,5,0"
                                 FontFamily="Segoe UI" 
                                 FontSize="15" 
                                 HorizontalContentAlignment="Stretch" 
                                 ItemContainerStyle="{DynamicResource ListBoxItemStyle_Metro}" 
                                 ItemTemplate="{DynamicResource TaskListItemTemplate}"                           
                                 ItemsSource="{Binding AllItems}"
                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                                 SelectedItem="{Binding SelectedTask, UpdateSourceTrigger=PropertyChanged}"
                                 ContextMenu="{DynamicResource TaskContextMenu}" Background="{x:Null}" />
                </Grid>
            </TabItem>            
            <TabItem Header=" pending" IsSelected="{Binding PendingItemsViewIsVisible}">
                    <Grid Margin="0,10,-5,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <!--Make sure to set the ElmentName and Path correctly when using ListHeaderContol-->
                        <localControls:ListHeaderControl Text="{Binding PendingItems.Count, StringFormat=' \{0\} TASKS '}" 
                                                         SortButtonText="{Binding PendingItemsSort, Converter={StaticResource sortByConverter}, StringFormat=BY \{0\}}"
                                                         SortButtonCommand="{Binding SortPendingItemsCommand}" Margin="0,-10,8,0" VerticalAlignment="Top"/>
                        <ListBox x:Name="ListBox_PendingItems"                     
                                 BorderThickness="0" 
                                 FontFamily="Segoe UI" 
                                 Margin="0,22,5,0"
                                 
                                 FontSize="15" 
                                 
                                 HorizontalContentAlignment="Stretch" 
                                 ItemContainerStyle="{DynamicResource ListBoxItemStyle_Metro}"
                                 ItemTemplate="{DynamicResource TaskListItemTemplate}" 
                                 ItemsSource="{Binding PendingItems}" 
                                 ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                                 SelectedItem="{Binding SelectedTask, UpdateSourceTrigger=PropertyChanged}"
                                 ContextMenu="{DynamicResource TaskContextMenu}"  />
                </Grid>
            </TabItem>
            <TabItem Header=" completed" IsSelected="{Binding CompletedItemsViewIsVisible}">
                    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,10,-5,0">
                        <!--Make sure to set the ElementName and Path correctly when using ListHeaderContol-->
                        <localControls:ListHeaderControl Text="{Binding CompletedItems.Count, StringFormat=' \{0\} TASKS '}" 
                                                         SortButtonText="{Binding CompletedItemsSort, Converter={StaticResource sortByConverter}, StringFormat=BY \{0\}}"
                                                         SortButtonCommand="{Binding SortCompletedItemsCommand}" Margin="0,-10,8,0" VerticalAlignment="Top"/>
                        <ListBox x:Name="ListBox_CompletedItems"
                             Margin="0,22,5,0"
                             BorderThickness="0"
                             FontFamily="Segoe UI" 
                             FontSize="15" 
                             HorizontalContentAlignment="Stretch" 
                             ItemContainerStyle="{DynamicResource ListBoxItemStyle_Metro}"
                             ItemTemplate="{DynamicResource TaskListItemTemplate}" 
                             ItemsSource="{Binding CompletedItems}" 
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                             SelectedItem="{Binding SelectedTask, UpdateSourceTrigger=PropertyChanged}"
                             ContextMenu="{DynamicResource TaskContextMenu}" Background="{x:Null}" />
                    </Grid>
                
                </TabItem>
            
            </TabControl>

		</Grid>



        <ListBox Height="35" Width="186" BorderBrush="Transparent" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,5,0,0"  
                ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                ItemsSource="{Binding Items, ElementName=tabControl}" SelectedItem="{Binding SelectedItem, ElementName=tabControl, Mode=TwoWay}" 
                Style="{StaticResource ListBoxStyle_Horizontal}" ItemContainerStyle="{StaticResource ListBoxItemStyle_Pivot}" FontSize="16">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Header}"  HorizontalAlignment="Right" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>        


        <TextBlock Height="21.96" Margin="7,0,191,0" TextWrapping="Wrap" Text="{Binding ListHeader}" Visibility="Collapsed" FontFamily="Segoe WP" FontWeight="Bold" VerticalAlignment="Top" FontSize="12"/>
        <StackPanel Height="38" HorizontalAlignment="Center" Margin="0" x:Name="stackPanel1" VerticalAlignment="Bottom" Orientation="Horizontal">
            <Button Width="30" x:Name="btn_addTask" Command="{Binding AddTaskCommand}" Visibility="Visible" Height="30" Style="{StaticResource ButtonStyle_Metro}" FontWeight="Bold" FontSize="22" ToolTip="Add Task">
                
				<Viewbox HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  					<Canvas  Height="50" Width="50">
      					<Path Stroke="{Binding Foreground, ElementName=btn_addTask}" StrokeThickness="4" Data="M 25,10 L 25,40 M 10,25 L 40,25" />
      					<Ellipse Height="50" Width="50" Stretch="Fill" StrokeThickness="3" Stroke="{Binding Foreground, ElementName=btn_addTask}"/>
  					</Canvas>
  				</Viewbox>
            
			</Button>
        </StackPanel>
        
        
    </Grid>
    
</UserControl>
